﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Helpers;
using MallInteractiveMap.Language;

namespace MallInteractiveMap.CMSWebClient
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ProcessAuthentication();
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            SetUICulture();
        }



        private void ProcessAuthentication()
        {
            NavigationMenu.Visible = Request.IsAuthenticated;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            SetLanguageAndResources();
        }

        protected void ChangeLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["CurrentCulture"] = Convert.ToInt32(ChangeLanguage.SelectedValue) == 1 ? Constants.Culture.US : Constants.Culture.Arabic;
            SetUICulture();
            Response.Redirect(Request.Url.ToString());
        }

        private void SetUICulture()
        {
            if (Session["CurrentCulture"] == null)
            {
                Session["CurrentCulture"] = "en-US";
            }
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Convert.ToString(Session["CurrentCulture"]));
            ChangeLanguage.SelectedValue =  Convert.ToString((int)LanguageLoader.CurrentLanguageType);
        }

        private void SetLanguageAndResources()
        {
            LoginStatus loginStatus = HeadLoginView.FindControl("HeadLoginStatus") as LoginStatus;
            if (loginStatus != null)
            {
                loginStatus.LogoutText = LanguageLoader.GetText("LOG_OUT");
            }
            NavigationMenu.Items[0].Text = LanguageLoader.GetText("HOME");
            NavigationMenu.Items[1].Text = LanguageLoader.GetText("MALL");
            NavigationMenu.Items[2].Text = LanguageLoader.GetText("FLOOR");
            NavigationMenu.Items[3].Text = LanguageLoader.GetText("CATEGORY");
            //NavigationMenu.Items[4].Text = LanguageLoader.GetText("MAP");
            NavigationMenu.Items[4].Text = LanguageLoader.GetText("SHOP");
            NavigationMenu.Items[5].Text = LanguageLoader.GetText("ABOUT");
        }
    }
}
